#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QIcon>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

//    qDebug() << "-----------------";
//    qDebug() << "QWidget初始化前";
//    getGeometry();
//    qDebug() << "-----------------";

    //使用绝对路径不安全
    //QIcon icon("D:/Administrator/Pictures/C.jpg");
    //使用qrc静态编译导入文件内容
    QIcon icon(":/C.jpg");
    this->setWindowIcon(icon);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pbt_title_clicked()
{
	//这里对控件设置标题是无效的
	//例如
    //ui->pbt_title->setWindowTitle(ui->lineEdit->text());
    //该语句可以执行 但是本身是错误的 只有最外层的Widget可以设置标题 但是也不会报错
    this->setWindowTitle(ui->lineEdit->text());
}

void Widget::getGeometry()
{
    qDebug() << "geometry: " << this->geometry();
    qDebug() << "frameGeometry: " << this->frameGeometry();
}

void Widget::on_getGeometry_clicked()
{
    getGeometry();
}

void Widget::on_addOpacity_clicked()
{
    float opacity = this->windowOpacity();
    if(opacity >= 1.0) return;
    qDebug() << "opacity: "<<opacity;
    opacity += 0.1;
    this->setWindowOpacity(opacity);
}

void Widget::on_subOpacity_clicked()
{
    float opacity = this->windowOpacity();
    if(opacity < 0.1) return;
    qDebug() << "opacity: "<<opacity;
    opacity -= 0.1;
    this->setWindowOpacity(opacity);
}
